package com.lc.yygh.hosp.controller;

import com.lc.yygh.common.result.Result;
import com.lc.yygh.hosp.service.HospitalService;
import com.lc.yygh.model.hosp.Hospital;
import com.lc.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@Api(tags = "医院管理")//这个注解作用只是为了让swagger这个后台页面有点中文，看着更清晰，跟代码逻辑没一点关系
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin  用了GetWay来解决跨域问题就不能用这个注解了，会冲突
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;

    //分页查询结果
    @ApiOperation(value = "获取分页列表")
    @PostMapping("{page}/{limit}")
    public Result findHospitalList(@ApiParam(name = "page", value = "当前页码", required = true)
                                   @PathVariable Integer page,

                                   @ApiParam(name = "limit", value = "每页记录数", required = true)
                                   @PathVariable Integer limit,

                                   @ApiParam(name = "hospitalQueryVo", value = "查询对象", required = false)
                                   @RequestBody HospitalQueryVo hospitalQueryVo){
        Page<Hospital> page1 = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return Result.success(page1);
    }

    //更新医院上线状态
    @ApiOperation(value = "更新上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result lock(
            @ApiParam(name = "id", value = "医院id", required = true)
            @PathVariable("id") String id,
            @ApiParam(name = "status", value = "状态（0：未上线 1：已上线）", required = true)
            @PathVariable("status") Integer status){
        hospitalService.updateStatus(id, status);
        return Result.success();
    }

    @ApiOperation(value = "获取医院详情")
    @GetMapping("show/{id}")
    public Result show(
            @ApiParam(name = "id", value = "医院id", required = true)
            @PathVariable String id) {
        //根据getDetail得到的医院详情包括两部分：基础属性和预约规则
        return Result.success(hospitalService.getDetail(id));
    }
}
